﻿namespace hedefgrup.reports.renault.implementation
{
    using hedefgrup.reports.renault;
    using hedefgrup.reports.renault.definitions;
    using System;
    using System.Collections.Generic;

    public class question
    {
        public int baseCount;
        public string code;
        public SortedList<int, int> optionCounts = new SortedList<int, int>();
        private dataCache sourceData;

        public question(dataCache sourceData, string code)
        {
            this.code = code;
            this.sourceData = sourceData;
            foreach (int num in this.getDefinition().optionDefinitions.Keys)
            {
                this.optionCounts.Add(num, 0);
            }
        }

        public void appendOptionCount(int option)
        {
            this.appendOptionCount(option, 1);
        }

        public void appendOptionCount(int option, int count)
        {
            if (this.optionCounts.ContainsKey(option))
            {
                SortedList<int, int> list;
                int num;
                (list = this.optionCounts)[num = option] = list[num] + count;
            }
        }

        public double calculateFormula1()
        {
            return ((((this.getYesCount() + this.getNoCount()) + this.getNACount()) > 0.0) ? (this.getYesCount() / ((this.getYesCount() + this.getNoCount()) + this.getNACount())) : 0.0);
        }

        public double calculateFormula2()
        {
            return this.calculateQvn();
        }

        public double calculateOptionPercentage(int option)
        {
            return ((this.baseCount > 0) ? (Convert.ToDouble(this.getOptionCount(option)) / Convert.ToDouble(this.baseCount)) : 0.0);
        }

        public double calculateQvn()
        {
            return ((((this.getYesCount() + this.getNoCount()) + this.getNACount()) > 0.0) ? ((this.getYesCount() - this.getNoCount()) / ((this.getYesCount() + this.getNoCount()) + this.getNACount())) : 0.0);
        }

        public questionDefinition getDefinition()
        {
            return this.sourceData.questionDefinitions[this.code];
        }

        public double getNACount()
        {
            return (double) this.getOptionCount(9);
        }

        public double getNoCount()
        {
            return (double) this.getOptionCount(2);
        }

        public int getOptionCount(int option)
        {
            return (this.optionCounts.ContainsKey(option) ? this.optionCounts[option] : 0);
        }

        public double getYesCount()
        {
            return (double) this.getOptionCount(1);
        }
    }
}

